<script setup lang="ts">
import * as echarts from 'echarts'

var getName = ['总院门诊', '通河门诊', '共江门诊', '通四门诊', '呼玛门诊']
var getValue = [1174, 844, 714, 682, 577]
var max = Math.max.apply(null, getValue)
var getMax = []
for (let i = 0; i < getName.length; i++) {
  getMax.push(max + 100)
}
// console.log(getMax)

const option = {
  backgroundColor: '#003366',
  grid: {
    left: '5%',
    right: '2%',
    bottom: '10',
    top: 30,
    containLabel: true
  },
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'none'
    },
    formatter: function (params) {
      return params[0].name + ' : ' + params[0].value
    }
  },
  xAxis: {
    show: false,
    type: 'value'
  },
  yAxis: [
    {
      type: 'category',
      inverse: true,
      offset: 10,

      axisLabel: {
        show: true,
        fontSize: '20',
        // align: 'center',

        color: '#fff'
      },
      splitLine: {
        show: false
      },
      axisTick: {
        show: false
      },
      axisLine: {
        show: false
      },
      data: getName
    },
    {
      type: 'category',
      inverse: true,
      offset: -5,
      axisTick: 'none',
      axisLine: 'none',
      show: true,
      axisLabel: {
        color: '#ffffff',
        fontSize: '20'
      },
      data: getValue
    }
  ],
  series: [
    {
      name: '值',
      type: 'bar',
      zlevel: 1,
      itemStyle: {
        borderRadius: 30,
        color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
          {
            offset: 0,
            color: 'rgb(128,204,255,1)'
          },
          {
            offset: 1,
            color: 'rgb(46,200,207,1)'
          }
        ])
      },
      barWidth: 20,
      data: getValue
    },
    {
      name: '背景',
      type: 'bar',
      barWidth: 20,
      barGap: '-100%',
      data: getMax,
      itemStyle: {
        color: 'rgba(24,31,68,1)',
        borderRadius: 30
      }
    }
  ]
}
const charts = ref()
onMounted(() => {
  let myecharts = echarts.init(charts.value)
  // 设置echarts配置项
  myecharts.setOption(option)
})
</script>

<template>
  <div class="box1">
    <div class="top">
      <p class="title">当日门诊人次</p>
      <p class="bg"></p>
    </div>
    <div class="charts" ref="charts"></div>
  </div>
</template>

<style lang="scss" scoped>
.box1 {
  background: url(../images/dataScreen-main-lb.png) no-repeat;
  background-size: 100% 100%;
  margin-top: 10px;
  .top {
    margin: 10px 0 0 20px;
    .title {
      color: white;
      font-size: 20px;
    }
    .bg {
      width: 100px;
      height: 7px;
      background: url(../images/dataScreen-title.png) no-repeat;
      background-size: 100% 100%;
      margin-top: 20px;
    }
  }

  .charts {
    margin-top: 40px;
    width: 100%;
    height: 320px;
  }
}
</style>
